package main

import (
	"fmt"
)

// work_pool
func work(id int, jobs <-chan int, result chan<- int) {

	for job := range jobs {
		fmt.Printf("work:%d start job:%d\n", id, job)
		result <- job * 2
		//time.Sleep(time.Microsecond * 500)
		fmt.Printf("work:%d stop job:%d\n", id, job)
	}
}

func main() {

	jobs := make(chan int, 100)
	result := make(chan int, 100)

	// 开启3个goroutine
	for a := 0; a < 3; a++ {
		go work(a, jobs, result)
	}

	// 发送5个任务
	for b := 0; b < 5; b++ {
		jobs <- b
	}
	for i := 0; i < 3; i++ {
		ret := <-result
		fmt.Println(ret)
	}
	close(jobs)
}
